package game.core
{
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	
	import game.core.util.DisplayUtil;
	
	/**
	 * 整个游戏里会有以下几种元素
	 * 	1.小球---->运动
	 *  2.砖块---->静止(点击弹起,点击消失)
	 *  3.子弹(可另分出来)(分不同种子子弹
	 *  4.减速机(减速度)
	 *  5.掉落的物品(物品可能有很多种)(只有一个方向的运动)
	 *  6.小怪物
	 */ 
	public class GameObject extends Sprite implements IDataRender,IGameObject,IDispose
	{
		public function GameObject()
		{
			super();
			this.addEventListener(Event.ADDED_TO_STAGE,addToStageHandler);
		}
		
		private var _movabled:Boolean;// 有些砖头类似的内容不可以穿过需要判断
		
		public function set movabled(value:Boolean):void {
			this._movabled = value;
		}
		
		public function get movabeld():Boolean {
			return this._movabled;
		}
		
		private function addToStageHandler(event:Event):void {
			this.removeEventListener(Event.ADDED_TO_STAGE,addToStageHandler);
			this.createChildren();
		}
		
		private var _fixed:Boolean;// 是否可以运动
		
		public function set fixed(value:Boolean):void {
			this._fixed = value;
		}
		
		public function get fixed():Boolean {
			return this._fixed;
		}
		
		private var _collidable:Boolean = true;// 是否可以碰撞,默认的同种类型的物体是可以碰撞的
		
		public function set collidable(value:Boolean):void {
			this._collidable = value;
		}
		
		public function get collidable():Boolean {
			return this._collidable;
		}
		
		private var _pause:Boolean;// 暂停的时候,其它的内容是不动的
		
		public function set pause(value:Boolean):void {
			this._pause = value;
		}
		
		public function get pause():Boolean {
			return this._pause;
		}
		
		
		
		/**
		 * 创建相应的对象
		 */ 
		protected function createChildren():void {
			
		}
		
		public function dispose():void {
			DisplayUtil.removeAllChildren(this);
		}
		
		/**
		 * 每个物体和子弹碰撞之后,都需要执行这里面的方法
		 */ 
		public function execute():void {
			
		}
		
		private var _data:Object;
		
		public function set data(value:Object):void {
			this._data = value;
		}
		
		public function get data():Object {
			return this._data;
		}
		
		private var _gName:String;// 必须要传递的一个内容,使用NameUtil来处理
		
		public function set gName(value:String):void {
			this._gName = value;
		}
		
		public function get gName():String {
			return this._gName;
		}
		
		public function hitTest(value:GameObject):Boolean {
			return super.hitTestObject(value);
			/* var result:Boolean = false;
			var bitmapData:BitmapData = new BitmapData(this.width,this.height,true,0xFFFFFF);
			bitmapData.draw(this);
			var hitBitmapData:BitmapData = new BitmapData(value.width,value.height,true,0xFFFFFF);
			hitBitmapData.draw(value);
			result = bitmapData.hitTest(new Point(this.x,this.y),0,hitBitmapData,new Point(value.x,value.y),0);
			bitmapData.dispose();
			hitBitmapData.dispose();
			return result; */
		}
	}
}